package com.example.springbootinit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @program: springboot1
 * @description:
 * @author: zhanghz001
 * @create: 2020-12-08 11:18
 **/
@Controller
public class HelloController {
    @Value("${name}")
    public String name1;

    @Value("${person.name}")
    private String name2;

    @Value("${address1[0]}")
    private String address11;

    @Value("${msg1}")
    private String msg1;
    @Value("${msg2}")
    private String msg2;
    @Value("${person3.name}")
    private String name11;
    //三种方式注入
    @Autowired
    private Environment environment;

    @Autowired
    private Person person;

    @RequestMapping("/hello2")
    public String hello2() {
        // System.out.println(name1);
        // System.out.println(name2);
        // System.out.println(address11);
        // System.out.println(msg1);
        // System.out.println(msg2);
        // System.out.println(name11);

        //environment
        // System.out.println(environment.getProperty("person.name"));
        // System.out.println(environment.getProperty("address1[0]"));
        // System.out.println(environment.getProperty("person3.name"));
        // System.out.println(environment.getProperty("msg2"));

        //ConfigurationProperties
        System.out.println();
        System.out.println(person);

        return "hello world";
    }

}
